package com.xwm93up.javatips.mapper;

import com.xwm93up.javatips.dto.ProductDto;
import com.xwm93up.javatips.exception.ProductValidatorException;
import com.xwm93up.javatips.po.Product;
import com.xwm93up.javatips.validator.ProductValidator;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.factory.Mappers;

import java.util.UUID;

/**
 * @Description: desc
 * @Author: xwm93up
 * @Since: 2021/10/27 18:39
 */
@Mapper(uses = {ProductValidator.class},imports = {UUID.class})
public interface ProductExceptionMapper {
    ProductExceptionMapper INSTANCE = Mappers.getMapper(ProductExceptionMapper.class);

    @Mapping(target = "id",constant = "-1L")
    @Mapping(source = "count",target = "count",defaultValue = "1")
    @Mapping(target = "productSn",expression = "java(UUID.randomUUID().toString())")
    ProductDto toDto(Product product) throws ProductValidatorException;
}
